<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户端-发布新任务</title>
    <link rel="stylesheet" href="./layui2_9/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">

    <!-- 内容主体区域-->
    <div class="layui-body">
        <div style="padding: 30px;" class="layui-fluid">
            <div class="layui-row">
                <div class="layui-col-md12">
                    <span class="layui-badge-dot"></span> <span
                        class="layui-badge-dot layui-bg-orange"></span> <span
                        class="layui-badge-dot layui-bg-green"></span> <span
                        class="layui-badge-dot layui-bg-cyan"></span> <span
                        class="layui-badge-dot layui-bg-blue"></span> <span
                        class="layui-badge-dot layui-bg-black"></span> <span
                        class="layui-badge-dot layui-bg-gray"></span>
                    <fieldset class="layui-elem-field layui-field-title"
                              style="margin-top: 30px;">
                        <legend>发布新任务</legend>
                    </fieldset>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-md1">&nbsp;</div>
                <div class="layui-col-md10">
                    <fieldset class="layui-elem-field">
                        <legend>填写新任务信息</legend>
                        <form id="reform" class="layui-form layui-form-pane"
                              lay-filter="formFilter" action="userTask.html" method="post"
                              style="padding: 30px;">

                            <div class="layui-form-item">
                                <label class="layui-form-label">任务标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="taskname" autocomplete="off"
                                           lay-verify="taskname" placeholder="请输入标题" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">奖励</label>
                                <div class="layui-input-block">
                                    <input type="text" name="reward" autocomplete="off"
                                           lay-verify="reward" placeholder="请输入奖励" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-inline">
                                    <label class="layui-form-label">学校</label>
                                    <div class="layui-input-block" style="width: 840px;">
                                        <input name="" placeholder="输入选择" class="layui-input" id="ID-dropdown-demo-base-input">
                                    </div>
                                </div>
                            </div>


                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">详细描述</label>
                                <div class="layui-input-block">
										<textarea name="taskcontext" placeholder="请输入内容"
                                                  class="layui-textarea" lay-verify="taskcontext"></textarea>
                                </div>
                            </div>

                                <div class="layui-form-item">
                                    <button class="layui-btn" lay-submit="reform"
                                            lay-filter="reform">发布
                                    </button>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-disabled"
                                            lay-submit="reform" lay-filter="reform">状态被限制，无法发布
                                    </button>
                                </div>

                        </form>
                    </fieldset>

                </div>
                <div class="layui-col-md1">&nbsp;</div>
            </div>

        </div>

    </div>

    <div class="layui-footer" align="center">
        <!-- 底部固定区域 -->
        © - 联系校事达官方客服：6666666
    </div>
</div>
<script src="./layui2_9/layui.js"></script>

<script>
    //JavaScript代码区域
    layui.use('element', function () {
        var element = layui.element;
        // 监听侧边导航栏的点击事件
        element.on('nav(test)', function (elem) {
            var parentLi = elem.closest('li.layui-nav-item');
            var allNavItems = document.querySelectorAll('.layui-nav-tree.layui-nav li.layui-nav-item');
            // 遍历所有导航项
            allNavItems.forEach(function (item) {
                if (item!== parentLi) {
                    // 关闭其他导航项的子菜单
                    var childMenu = item.querySelector('dl.layui-nav-child');
                    if (childMenu) {
                        // 移除 layui-nav-itemed 类以关闭菜单
                        // item.classList.remove('layui-nav-itemed');
                    }
                }
            });
            // 切换当前点击的导航项的展开/关闭状态
            // parentLi.addClass("layui-nav-itemed")
        });
    });
</script>

<script>
    layui.use(['form', 'layedit', 'laydate', 'jquery'], function () {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            $ = layui.$,
            laydate = layui.laydate;

        //自定义验证规则
        form.verify({
            taskname: function (value) {
                if (value.length < 2) {
                    return '标题太短了啊';
                }
            },
            reward: function (value) {
                if (value.length <= 0) {
                    return '请输入奖励内容';
                }
            },
            taskcontext: function (value) {
                if (value.length < 1) {
                    return '任务详细描述太短';
                }
            },
            publishScholName: function (value) {
                if (value.length <= 0) {
                    return '请选择学校';
                }
            }
        });

        //创建一个编辑器
        layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(reform)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
                title : '最终的提交信息'
            })*/
            //return false;
        });


        $(function () {
            form.on('select(publishSchoolId)', function (data) {
                $("#publishSchoolName").val(this.innerHTML);
            });


            $.post(
                "userNewtask.html",
                function (data) {
                    var obj = JSON.parse(data);
                    var str = "";
                    for (var i = 0; i < obj.length; i++) {
                        var optionStr = "";
                        optionStr += "<option value='" + obj[i].schoolid + "'>" + obj[i].name + "</option>";
                        $("#publishSchoolId").append(optionStr);
                        form.render('select', 'formFilter');

                        $("#publishSchoolName").val(obj[0].name);
                    }
                }
            );
        });


    });


</script>
<script>
    layui.use(function(){
        var dropdown = layui.dropdown;
        // 绑定输入框
        dropdown.render({
            elem: '#ID-dropdown-demo-base-input',
            closeOnClick: false, // 不开启“打开与关闭的自动切换”，即点击输入框时始终为打开状态
            data: [{
                title: '中南大学',
                id: 101
            },{
                title: '湖南大学',
                id: 102
            },{
                title: '长沙大学',
                id: 103
            }],
            click: function(obj){
                this.elem.val(obj.title);
            },
            style: 'min-width: 235px;'
        })
    });
</script>
<script>
    function showPrivate(value) {
        window.sessionStorage.setItem("username",value);
        //iframe层
        layer.open({
            type: 2,
            title: '即时通信',
            shade: 0.6, // 遮罩透明度
            shadeClose: true, // 点击遮罩区域，关闭弹层
            area: ['1000px', '600px'],
            content: 'userTalk.html'
        });
    }
</script>
</body>
</html>
